package dao

import (
	"gorm.io/gorm"
	"vue-element-plus-admin-go/model"
)

type DictDao struct {
	db *gorm.DB
}

// GetById 根据id查询
func (dao *DictDao) GetById(id int64) (error, *model.Dict) {
	m := &model.Dict{Id: id}
	if result := dao.db.First(m, 1); result.Error != nil {
		return result.Error, m
	}
	return nil, m
}

// Create 插入数据返回id
func (dao *DictDao) Create(m *model.Dict) error {
	if result := dao.db.Create(m); result.Error != nil {
		return result.Error
	}
	return nil
}

// UpdateById 根据id更新
func (dao *DictDao) UpdateById(m *model.Dict) error {
	if result := dao.db.Save(m); result.Error != nil {
		return result.Error
	}
	return nil
}

// DeleteById 根据id 删除
func (dao *DictDao) DeleteById(id int64) error {
	m := model.Dict{Id: id}
	if result := dao.db.Delete(&m); result.Error != nil {
		return result.Error
	}
	return nil
}
